<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.44">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #000000}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #000000; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
span.s1 {font: 18.0px Helvetica}
span.s2 {color: #0000bf}
span.s3 {color: #000000}
span.s4 {color: #bf0000}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><span class="s1"><b>Dfsm<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></b></span><b>demand rate finite state machine</b></p>
<p class="p2"><br></p>
<p class="p1"><b>Dfsm(rules, n, randgen)</b></p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p1">Similar to <a href="SC://Pfsm">Pfsm</a>, <b>Dfsm</b> implements a markov chain. Each state has a number of next states out of which one is randomly chosen.</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p1"><b>rules</b> - array in the format:<span class="Apple-converted-space"> </span></p>
<p class="p1">[</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span> [ entry states ],</p>
<p class="p1"><span class="Apple-tab-span">	</span> <span class="Apple-tab-span">	</span>item, [ next states ],</p>
<p class="p1"><span class="Apple-tab-span">	</span> <span class="Apple-tab-span">	</span>item, [ next states ],</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span> ...</p>
<p class="p1"><span class="Apple-tab-span">	</span> <span class="Apple-tab-span">	</span>end item</p>
<p class="p1"><span class="Apple-converted-space"> </span>]</p>
<p class="p2"><br></p>
<p class="p1">Each <b>item</b> can be a number, or a ugen, typically demand rate. If no <b>end item</b> is given, <b>0.0</b> is used as default.</p>
<p class="p2"><span class="Apple-converted-space"> </span></p>
<p class="p1"><b>n</b> - number of items from each state to embed. If <b>inf</b>, they are embedded completely.</p>
<p class="p2"><br></p>
<p class="p1"><b>randgen </b>- demand rate random number generator that should ouput values between 0.0 and 1.0. If a deterministic ugen is used, the choice of next states of the finite state machine can be controlled (i.e. 0 will allways choose the first, 1 always the last, else in between).</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p3"><br></p>
<p class="p3"><br></p>
<p class="p3"><br></p>
<p class="p4">s.boot;</p>
<p class="p3"><br></p>
<p class="p5">// random jumps</p>
<p class="p4">(</p>
<p class="p4">{</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s2">var</span> a, b, trig = <span class="s2">Impulse</span>.kr(<span class="s2">MouseX</span>.kr(4, 100, 1));</p>
<p class="p4"><span class="Apple-tab-span">	</span>a = <span class="s2">Dfsm</span>([[1], 1.5, [0, 1], 2.5, [0, 1]]);</p>
<p class="p4"><span class="Apple-tab-span">	</span>b = <span class="s2">Demand</span>.kr(trig, 0, a).poll(trig);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s2">SinOsc</span>.ar(b * 200 + 300) * 0.1</p>
<p class="p4">}.play</p>
<p class="p4">);</p>
<p class="p3"><br></p>
<p class="p5">// 2.5 may come after 1.5, but not the other way round.</p>
<p class="p4">(</p>
<p class="p4">{</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s2">var</span> a, b, trig = <span class="s2">Impulse</span>.kr(<span class="s2">MouseX</span>.kr(4, 100, 1));</p>
<p class="p4"><span class="Apple-tab-span">	</span>a = <span class="s2">Dfsm</span>([[0], 1.5, [0, 0, 1], 2.5, [1, 2], 0.5, [0]]);</p>
<p class="p4"><span class="Apple-tab-span">	</span>b = <span class="s2">Demand</span>.kr(trig, 0, a).poll(trig);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s2">SinOsc</span>.ar(b * 200 + 300) * 0.1</p>
<p class="p4">}.play</p>
<p class="p4">);</p>
<p class="p3"><br></p>
<p class="p3"><br></p>
<p class="p3"><br></p>
<p class="p5">// embed demand ugens, embed 2 of each, end with series of 4, 5, 3.</p>
<p class="p4">(</p>
<p class="p4">{</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s2">var</span> a, n = 2, trig = <span class="s2">Impulse</span>.kr(<span class="s2">MouseX</span>.kr(4, 100, 1));</p>
<p class="p4"><span class="Apple-tab-span">	</span>a = <span class="s2">Dfsm</span>([</p>
<p class="p5"><span class="s3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>[0], </span>// entry states</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">Dseq</span>([-2, -3], <span class="s2">inf</span>), [1],<span class="Apple-converted-space"> </span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">Dseq</span>([1, 2, 1.5], <span class="s2">inf</span>), [0, 0, 0, 1, 2],<span class="Apple-converted-space"> </span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">Dseq</span>([4, 5, 3], <span class="s2">inf</span>) <span class="s4">// exit state</span></p>
<p class="p4"><span class="Apple-tab-span">	</span>], n);</p>
<p class="p4"><span class="Apple-tab-span">	</span>b = <span class="s2">Demand</span>.kr(trig, 0, a).poll(trig);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s2">SinOsc</span>.ar(b * 200 + 700) * 0.1</p>
<p class="p4">}.play</p>
<p class="p4">);</p>
<p class="p3"><br></p>
<p class="p3"><br></p>
<p class="p5">// direct audification</p>
<p class="p4">(</p>
<p class="p4">{</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s2">var</span> a, b, pseudorandomness;</p>
<p class="p4"><span class="Apple-tab-span">	</span>pseudorandomness = <span class="s2">Dswitch1</span>((0..1000).scramble / 1000, <span class="s2">Dwhite</span>(0, 1, <span class="s2">inf</span>)</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>* <span class="s2">MouseY</span>.kr(1, 1000, 1));</p>
<p class="p4"><span class="Apple-tab-span">	</span>a = {<span class="Apple-converted-space"> </span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">var</span> next = { { #[0, 1, 2, 3].choose } ! rrand(2, 5) };</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>var n = 2;</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">var</span> d = <span class="s2">Dfsm</span>([</p>
<p class="p6"><span class="s3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></span>next.value<span class="s3">,<span class="Apple-converted-space"> </span></span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">Dseq</span>([0, 0, 1], <span class="s2">inf</span>), <span class="s3">next.value</span>,</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">Dseq</span>([-1, 0].clipExtend(10.rand + 2), <span class="s2">inf</span>), <span class="s3">next.value,</span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">Dseq</span>([1, 0, -1, 0].clipExtend(10.rand + 4), <span class="s2">inf</span>), <span class="s3">next.value,</span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">Dwhite</span>(0, 1, <span class="s2">inf</span>), <span class="s3">next.value,</span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>0</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>],<span class="Apple-converted-space"> </span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">MouseX</span>.kr(1, 1115, 1),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>pseudorandomness</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">Pan2</span>.ar(<span class="s2">Duty</span>.ar(<span class="s2">SampleDur</span>.ir, 0, d), <span class="s2">LFNoise1</span>.kr(1))</p>
<p class="p4"><span class="Apple-tab-span">	</span> } ! 5;</p>
<p class="p4"><span class="Apple-tab-span">	</span>a.sum * 0.1;</p>
<p class="p4">}.play</p>
<p class="p4">);</p>
<p class="p3"><br></p>
<p class="p3"><br></p>
<p class="p3"><br></p>
<p class="p3"><br></p>
</body>
</html>
